"""
2. 已知一个列表为 nums = [1,0,-1,-2,-3,2,3 ]，target = 0 ，找到所有的满足数组内三个数相加等于target的组合，不能使用穷举法。
"""
import copy


def find_out_combinations(xlist, target):
    result = []
    xlist = list(xlist)
    for i in range(len(xlist)):
        xcopy = copy.deepcopy(xlist)
        first = xcopy.pop(i)
        for j in range(len(xcopy)):
            xcopy02 = copy.deepcopy(xcopy)
            second = xcopy02.pop(j)
            for third in xcopy02:
                if target == first + second + third:
                    result.append((first, second, third, ))
    return result


def find_out_combinations_gen(xlist, target):
    xlist = list(xlist)
    for i in range(len(xlist)):
        xcopy = copy.deepcopy(xlist)
        first = xcopy.pop(i)
        for j in range(len(xcopy)):
            xcopy02 = copy.deepcopy(xcopy)
            second = xcopy02.pop(j)
            for third in xcopy02:
                if target == first + second + third:
                    yield first, second, third,


if '__main__' == __name__:

    def main():
        nums = [1, 0, -1, -2, -3, 2, 3, 4, 5, 6, -2, -3]
        target = 0
        result = find_out_combinations_gen(nums, target)
        print(next(result))
        print(next(result))

    main()
